AC_INIT([PFC Servidor], [1.0.0], [019250@comp.uems.br], [pfc-servidor], [http://moodle.alcionesytes.net])
AC_PREREQ([2.50])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([gnu 1.11 -Wall dist-xz])
AM_MAINTAINER_MODE([disable])
AC_CONFIG_MACRO_DIR([m4])
m4_pushdef([AC_INCLUDES_DEFAULT], [$1])
AC_COPYRIGHT([Ednei Leite da Silva])
AC_REVISION([$Revision: 1.0.0 $])
AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
AC_CONFIG_HEADERS([config.h])

AC_PREFIX_DEFAULT([/etc/serverfw])

AC_CANONICAL_HOST

AC_MSG_NOTICE([Plataforma: $host_os])
case "$host_os" in
	linux*)
		WIN_LD=""
		WIN_libs=""
		;;
	*)
		WIN_LD="-mwindows -D_WIN32_WINNT=0x0501 -mms-bitfields"
		WIN_libs="-lws2_32"
		;;
esac
AC_SUBST([WIN_LD])
AC_SUBST([WIN_libs])

# Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_LANG([C])
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_CHECK_PROGS([LS], [ls], [/bin/ls], [$PATH])

# Checks for libraries.

AC_ARG_WITH(pcap-config, [	--with-pcap-config=DIR	pcap-config for LibPCAP],
[
if test "$withval" != no
then
	PCAP_CONFIG="$withval"
	if test ! -f "${PCAP_CONFIG}"
	then
		AC_MSG_ERROR([Could not find your LibPCAP installation])
	fi
fi
],
[
STANDARD_PREFIXES="/usr /usr/local /opt /local /mingw"
PCAP_CONFIG=""
for i in `echo "$STANDARD_PREFIXES"`; do
	if test -f "$i/bin/pcap-config"; then
		PCAP_CONFIG="$i/bin/pcap-config"
    	break;
    fi
done
])

if test x"$PCAP_CONFIG" = x; then
    AC_MSG_ERROR([$PACKAGE requires pcap_config])
fi

AC_SUBST([PCAP_LIBS],[`$PCAP_CONFIG --libs`])
AC_SUBST([PCAP_CFLAGS],[`$PCAP_CONFIG --cflags`])

# Checks for header files.
AC_CHECK_HEADERS([stdio.h stdlib.h string.h unistd.h sys/types.h sys/socket.h netinet/in.h netdb.h sinal.h errno.h err.h time.h arpa/inet.h])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

#Definicoes Locais
AC_DEFINE([DOCS], ["docs/"], [Caminho para os documentos do sistema])
#AC_DEFINE([BASE], ["base/firewall.db"], [Caminho para base de dados])

AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_LDFLAGS])
AC_SUBST([AM_LDADD])

AC_SUBST([SL_INCLUDE],["-I../sqlite/"])
AC_SUBST([SL_LDADD],["../sqlite/.libs/libsqlite3.a"])
AC_SUBST([SL_BIN],["../sqlite/sqlite3"])
AC_SEARCH_LIBS([lt_dlopen], [ltdl])
AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([pthread_mutexattr_init], [pthread])
AC_SEARCH_LIBS([crypt_r], [crypt])

#Definição do Cabeçalho
AH_TOP([
#ifndef __CONFIG_H__
#define __CONFIG_H__ 1

#if defined(__WIN32__) || defined(__WIN__)
	#include <windows.h>
#endif
])

#Definição de Rodapé
AH_BOTTOM([
#ifdef HAVE_IOSTREAM
	#include <iostream>
#endif
#ifdef HAVE_VECTOR
	#include <vector>
#endif
#ifdef HAVE_CMATH
	#include <cmath>
#endif
#ifdef HAVE_CSTDIO
	#include <cstdio>
#endif
#ifdef HAVE_CSTDLIB
	#include <cstdlib>
#endif
#ifdef HAVE_STDIO_H
	#include <stdio.h>
#endif
#ifdef HAVE_SYS_TYPES_H
	#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
  #include <sys/stat.h>
#endif
  #ifdef STDC_HEADERS
    #include <stdlib.h>
    #include <stddef.h>
  #else
  #ifdef HAVE_STDLIB_H
    #include <stdlib.h>
  #endif
#endif
#ifdef HAVE_STRING_H
  #if !defined STDC_HEADERS && defined HAVE_MEMORY_H
    #include <memory.h>
  #endif
  #include <string.h>
#endif
#ifdef HAVE_STRINGS_H
  #include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
  #include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
  #include <stdint.h>
#endif
#ifdef HAVE_UNISTD_H
  #include <unistd.h>
#endif
#ifdef HAVE_MATH_H
  #include <math.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
  #include <netinet/in.h>
#endif
#ifdef HAVE_NETDB_H
  #include <netdb.h>
#endif
#ifdef HAVE_FSTREAM
  #include <fstream>
#endif
#ifdef HAVE_ERRNO_H
  #include <errno.h>
#endif
#ifdef HAVE_TIME_H
  #include <time.h>
#endif
#ifdef HAVE_ARPA_INET_H
  #include <arpa/inet.h>
#endif
#endif /* __CONFIG_H__ */
])

AC_MSG_RESULT([Configurado com Sucesso!])
AC_CONFIG_FILES([Makefile src/Makefile docs/Makefile base/Makefile serverfw.sh serverfw-fedora.sh firewall])

#Depencias estáticas (Bibliotecas)
AC_CONFIG_SUBDIRS([sqlite])

AC_OUTPUT
